<template>
  <div id="" class="video">
    <div class="content">
      <div class="leftOperation">
        <div class="operationWrapper">
          <el-collapse class="collapse" v-model="activeName">
            <el-collapse-item name="1">
              <template slot="title">
                <img src="../../../../assets/img/video/yuan.png" alt="" style="margin-right: 15px">云台控制
              </template>
              <div class="telecontrol">
                <div class="button-group" >
                  <div class="outter-circle">
                    <div class="inner-parts" >
                      <div class="rotate"><img src="../../../../assets/img/video/shang.png" @mousedown="start(0)" @mouseup="stop(0)"></div>
                    </div>
                    <div class="inner-parts"  >
                      <div class="rotate"><img src="../../../../assets/img/video/you.png" @mousedown="start(3)" @mouseup="stop(3)"></div>
                    </div>
                    <div class="inner-parts" >
                      <div class="rotate"><img src="../../../../assets/img/video/zuo.png" @mousedown="start(2)" @mouseup="stop(2)"></div>
                    </div>
                    <div class="inner-parts"  >
                      <div class="rotate"><img src="../../../../assets/img/video/xia.png" @mousedown="start(1)" @mouseup="stop(1)"></div>
                    </div>
                    <div class="inner-circle" style="display: flex;justify-content: center;align-items: center;">
                      <img  v-show="play === true" class="rotate" @click="start(3, true)" style="display: inline-block;margin-left: 7px;margin-top: -5px" src="../../../../assets/img/video/bofang.png" alt="">
                      <img v-show="play === false" class="rotate" @click="stop(3)" style="display: inline-block;margin-left: 7px;margin-top: -5px" src="../../../../assets/img/video/stop.png" alt="">
                    </div>
                  </div>
                </div>
                <div class="control">
                  <div style="padding: 10px 10px 0 20px; margin-bottom: 12px">
                    <div class="input-group">
                      <div style="width: 100%;text-align: center" id="basic-addon1">
                        速度等级 &nbsp;&nbsp; {{ speed }}X
                      </div>
                      <el-slider v-model="speed" :step="1" :min="1" :max="3" />
                    </div>
                  </div>
                  <div class="controlContent">
                    <div class="controItem">
                      <i class="el-icon-minus reduce" @mousedown="start(11)" @mouseup="stop(11)"></i>
                      <span>调焦</span>
                      <i class="el-icon-plus increase" @mousedown="start(10)" @mouseup="stop(10)"></i>
                    </div>
                    <!-- <div class="controItem">
                       <i class="el-icon-minus reduce"></i>
                       <span>光圈</span>
                       <i class="el-icon-plus increase"></i>
                     </div>-->
                    <div class="controItem">
                      <i class="el-icon-minus reduce" @mousedown="start(9)" @mouseup="stop(9)"></i>
                      <span>变倍</span>
                      <i class="el-icon-plus increase" @mousedown="start(8)" @mouseup="stop(8)"></i>
                    </div>
                  </div>
                </div>
              </div>
            </el-collapse-item >
            <el-collapse-item name="2">
              <template slot="title">
                <img src="../../../../assets/img/video/yuan.png" alt="" style="margin-right: 15px">设备
              </template>
              <div :class="{'active': index === selectedIndex}" v-for="(item,index) in this.videoList" :key="index" class="equipmentList" @click="clickEquipmentList(index,item)">{{item.name}}</div>
            </el-collapse-item>
          </el-collapse>
        </div>
      </div>
      <div class="rightContent">
        <div class="rightHeader">
          <el-radio-group v-model="radio" class="rightRadio" @change="changeRadio">
            <el-radio :label="1">1屏</el-radio>
            <el-radio :label="4">4屏</el-radio>
            <el-radio :label="6">6屏</el-radio>
            <el-radio :label="12">12屏</el-radio>
          </el-radio-group>
        </div>
        <div class="rightVideo">
          <el-row class="videoItemWrap" v-if="this.radio === 1">
            <el-col :span="24" class="videoItem" v-for="(item,index) in this.videoPage" :key="index" >
              <!--              http://hls.open.ys7.com/openlive/cc11c2f56d914676becccdef12f2368f.m3u8-->
              <!--              src="http://hls.open.ys7.com/openlive/cc11c2f56d914676becccdef12f2368f.m3u8"-->
              <video
                :vname="item.name"
                :id="item.id"
                controls="controls"
                style="width: 100%;height: 100%;object-fit: fill"
                poster="[封面图片URL]"
                autoplay = true
                playsInline
                muted
                webkit-playsinline
                :src="item.address"
              >
                <!-- <source :src="item.address" type="application/x-mpegURL" /> -->
              </video>
              <Corner></Corner>
            </el-col>
          </el-row>
          <el-row class="videoItemWrap col4" v-if="this.radio === 4">
            <div class="col4Item" v-for="(item,index) in this.videoPage" :key="index" >
              <video
                :vname="item.name"
                :id="item.id"
                controls="controls"
                style="width: 100%;height: 100%;object-fit: fill"
                poster="[封面图片URL]"
                autoplay = true
                playsInline
                muted
                webkit-playsinline
              >
                <source :src="item.address" type="application/x-mpegURL" />
              </video>
              <Corner></Corner>
            </div>
          </el-row>
          <el-row class="videoItemWrap col6" v-if="this.radio === 6">
            <div class="col6Item" v-for="(item,index) in this.videoPage" :key="index">
              <video
                :vname="item.name"
                :id="item.id"
                controls="controls"
                style="width: 100%;height: 100%;object-fit: fill"
                poster="[封面图片URL]"
                autoplay = true
                playsInline
                muted
                webkit-playsinline
              >
                <source :src="item.address" type="application/x-mpegURL" />
              </video>
              <Corner></Corner>
            </div>
          </el-row>
          <el-row class="videoItemWrap col12" v-if="this.radio === 12">
            <div class="col12Item" v-for="(item,index) in this.videoPage" :key="index">
              <video
                :vname="item.name"
                :id="item.id"
                controls="controls"
                style="width: 100%;height: 100%;object-fit: fill"
                poster="[封面图片URL]"
                autoplay = true
                playsInline
                muted
                webkit-playsinline
              >
                <source :src="item.address" type="application/x-mpegURL" />
              </video>
              <Corner></Corner>
            </div>
          </el-row>
          <el-row class="videoItemWrap0" :style="{'width':videoWidth,'height':videoHeight+'px'}" v-if="this.radio === 0">
            <el-col :span="24" class="videoItem">
              <!--              http://hls.open.ys7.com/openlive/cc11c2f56d914676becccdef12f2368f.m3u8-->
              <!--              src="http://hls.open.ys7.com/openlive/cc11c2f56d914676becccdef12f2368f.m3u8"-->
              <video
                :vname="videoData0.name"
                :id="videoData0.id"
                controls="controls"
                style="width: 100%;height: 100%;object-fit: fill"
                poster="[封面图片URL]"
                autoplay = true
                playsInline
                muted
                webkit-playsinline
                :src="videoData0.address"
              >
                <!-- <source :src="videoData0.address" type="application/x-mpegURL" /> -->
              </video>
              <Corner></Corner>
            </el-col>
          </el-row>
          <div class="footer">
            <div class="paging info">
              <el-pagination @current-change="handleCurrentChange" :background="true" :current-page.sync="currentPage"
                             layout="prev, pager, next" :page-size="pageSize" :total="total" />
           </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Corner from '../../../../components/corner'
import Pagination from '../../../../components/Pagination'
import {EZUIPlayer} from '../../../../../static/EZUIKit/ezuikit'
import {VideoViewModelApi} from '../../../../api/Intelligence/video/videoViewModelApi'
let videoViewModelApi = new VideoViewModelApi()
export default {
  name: 'VideoView',
  components: {
    Corner, Pagination
  },
  data () {
    return {
      activeName: ['1', '2'],
      play: true,
      speed: 1,
      command: null,
      selectedIndex: 0,
      selectedVideo: {},
      total: 0,
      videoPage: [],
      clientHeight: '',
      clientWidth: '',
      videoWidth: '50%',
      videoHeight: '',
      radio: 4,
      pageSize: 4,
      videoList: [],
      currentPage: 1,
      videoData0: {},
      players: []
    }
  },
  destroyed () {
    this.stop()
    for (let i = 0; i < this.players.length; i++) {
      let player = this.players[i]
      player.stop()
    }
  },
  mounted () {
    this.clientHeight = `${document.documentElement.clientHeight}` // 获取浏览器可视区域高度
    this.clientWidth = `${document.documentElement.clientWidth}` // 获取浏览器可视区域宽度
    this.videoHeight = (this.clientHeight - 200) / 2
    this.findVideo()
  },
  methods: {
    loadPlayers () {
      for (let i = 0; i < this.videoPage.length; i++) {
        let id = this.videoPage[i].id
        let player = new EZUIPlayer(id)
        this.players.push(player)
      }
    },
    findVideo () {
      videoViewModelApi.findVideo().then(res => {
        let result = res.data.result
        if (res.data.message === 'success' && result) {
          this.videoList = result
          this.total = result.length
          this.selectedVideo = result[0]
          this.videoPage = result.slice(0, 4)
          this.$nextTick(function () {
            this.loadPlayers()
          })
        }
      })
    },
    changeRadio () {
      this.currentPage = 1
      this.pageSize = this.radio
      this.selectedIndex = 0
      this.selectedVideo = this.videoList[0]
      this.videoPage = this.videoList.slice(0, this.radio)
      this.$nextTick(function () {
        this.loadPlayers()
      })
    },
    handleCurrentChange (val) {
      this.currentPage = val
      this.stop(this.command)
      let start = (val - 1) * this.pageSize
      let end = start + this.pageSize
      this.selectedIndex = start
      this.selectedVideo = this.videoList[start]
      this.videoPage = []
      this.$nextTick(function () {
        this.videoPage = this.videoList.slice(start, end)
        this.$nextTick(function () {
          this.loadPlayers()
        })
      })
    },
    clickEquipmentList (index, data) {
      this.stop(this.command)
      this.radio = 1
      this.pageSize = 1
      this.selectedIndex = index
      this.selectedVideo = data
      this.currentPage = index + 1
      this.videoPage = [data]
      this.$nextTick(function () {
        this.loadPlayers()
      })
    },
    start (command, play) {
      if (!this.selectedVideo) {
        this.$message({
          message: '请选中需要控制的设备',
          type: 'warning'
        })
        return false
      }
      let serialNo = this.selectedVideo.deviceSerial
      let channel = this.selectedVideo.channel
      if (!serialNo) {
        this.$message.error('操作失败，该设备未设置序列号')
        return false
      }
      if (!channel) {
        this.$message.error('操作失败，该设备未设置通道号')
        return false
      }

      let direction = Number(command)
      let params = {
        serialNo: serialNo,
        channel: channel,
        direction: direction,
        speed: this.speed
      }
      videoViewModelApi.start(params).then(res => {
        if (res.data.message === 'success') {
          this.command = direction
          if (play) {
            this.play = false
          }
        }
      })
    },
    stop (command) {
      let serialNo = this.selectedVideo.deviceSerial
      let channel = this.selectedVideo.channel
      if (command && serialNo && channel) {
        let params = {
          serialNo: serialNo,
          channel: channel,
          direction: command
        }
        videoViewModelApi.stop(params).then(res => {
          if (res.data.message === 'success') {
            this.command = null
            this.play = true
          }
        })
      }
    }
  }
}
</script>
<style lang="less" scoped>
  .video{
    font-size: 1.6rem;
    color: white;
    width: 100%;
    height: 100%;
  }
  .content{
    padding-top: 1%;
    padding-bottom: 2%;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    display: inline-flex;
    .leftOperation{
      /*width: 14%;*/
      width: 256px;
      height: 100%;
      /*padding: 1% 1%;*/
      box-sizing: border-box;
      padding-top: 1%;
      border:1px solid rgba(3,222,238,1);
      overflow: hidden;
      min-width: 256px;
      .operationWrapper{
        position: relative;
        right: -17px;
        height: 100%;
        overflow-y: scroll;
        padding-right: 17px;
      }
      // 折叠面板
      .collapse{
        border: none;
        & /deep/ .el-collapse-item__header{
          width: 95%;
          font-size: 1.8rem;
          padding-left: 10px;
          border-bottom: none;
          background:linear-gradient(90deg,rgba(16,134,223,.5));
        }
        & /deep/ .el-collapse-item__wrap{
          border-bottom: none;
          background: none;
          text-align: center;
        }
        & /deep/ .el-collapse-item__content{
          padding-top: 10px;
          color:rgba(3,222,238,1);
          font-size: 1.8rem;
        }
        & /deep/ .el-collapse-item{
          margin-bottom: 20px;
        }
      }
      // 遥控
      .telecontrol{
        width: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        .button-group {
          margin: 15px 0;
          width: 200px;
          height: 200px;
          position: relative;
        }
        .outter-circle {
          width: 200px;
          height: 200px;
          background:linear-gradient(0deg,rgba(14,112,190,1),rgba(5,206,231,1));
          opacity:0.9;
          border-radius: 100%;
          overflow: hidden;
          transform-origin: center;
          transform: rotate(45deg);
        }
        .inner-parts {
          cursor: pointer;
          float: left;
          width: 100px;
          height: 100px;
          line-height: 100px;
          text-align: center;
        }
        .inner-circle {
          cursor: pointer;
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%,-50%);
          width: 80px;
          height: 80px;
          line-height: 80px;
          text-align: center;
          border-radius: 100%;
          background:linear-gradient(0deg,rgba(14,105,177,1),rgba(6,198,228,1));
        }
        .rotate {
          display: inline-block;
          transform: rotate(-45deg);
          position: relative
        }
        .rotate:active{
          top:2px;
        }
        .control{
          width: 100%;
          .controlTitle{
            margin-bottom: 15px;
          }
          .controlContent{

          }
          .controItem{
            font-size: 1.8rem;
            display: inline-flex;
            justify-content: space-between;
            align-items: center;
            width: 100%;
            margin-bottom: 10px;
            &:last-child{
              margin-bottom: 0;
            }
          }
          .reduce{
            font-size: 3rem;
            font-weight: 900;
            line-height: 38px;
            width:70px;
            height:38px;
            background:linear-gradient(88deg,rgba(7,152,186,1) 0%,rgba(16,98,163,1) 100%);
            position: relative;
          }
          .reduce:active{
            top: 2px;
          }
          .increase{
            font-size: 3rem;
            font-weight: 600;
            line-height: 38px;
            width:70px;
            height:38px;
            background:linear-gradient(88deg,rgba(7,152,186,1) 0%,rgba(16,98,163,1) 100%);
            position: relative;
          }
          .increase:active{
            top: 2px;
          }
        }
      }
      .equipmentList{
        cursor: pointer;
        &.active{
          -webkit-box-shadow: inset 0 0 15px #00f5ff;
          box-shadow: inset 0 0 6px #00f5ff;
        }
      }
    }
    .rightContent{
      position: relative;
      width: 100%;
      top: -75px;
      margin-left: 3%;
      height: calc(100vh - 125px);
      /*overflow: hidden;*/
      .rightHeader{
        margin-left: 10px;
      }
      .rightRadio{
        & /deep/ .el-radio__input.is-checked .el-radio__inner{
          background: none;
        }
        & /deep/ .el-radio__input.is-checked .el-radio__inner::after{
          border:2px solid rgba(0,255,255,1);
        }
      }
      .rightVideo{
        margin-top: 15px;
        height: 100%;
        .col4{
          .col4Item{
            padding: 1px;
            box-sizing: border-box;
            width: 48%;
            height: 49%;
            position: relative;
            display: inline-block;
            margin-bottom: 10px;
          }
          .col4Item:nth-of-type(1) {
            margin-right: 2%;
          }
          .col4Item:nth-of-type(3) {
            margin-right: 2%;
          }
        }
        .col6{
          min-width: 954px;
          .col6Item{
            padding: 1px;
            box-sizing: border-box;
            width: 32%;
            height: 49%;
            position: relative;
            display: inline-block;
            margin-bottom: 12px;
            margin-right: 1.5%;
          }
          .col6Item:nth-of-type(3) {
            margin-right: 0;
          }
          .col6Item:nth-of-type(6) {
            margin-right: 0;
          }
        }
        .col12{
          min-width: 1110px;
          .col12Item{
            padding: 1px;
            box-sizing: border-box;
            width: 24%;
            height: 32%;
            position: relative;
            display: inline-block;
            margin-bottom: .8%;
            margin-right: .9%;
          }
          .col12Item:nth-of-type(4) {
            margin-right: 0;
          }
          .col12Item:nth-of-type(8) {
            margin-right: 0;
          }
          .col12Item:nth-of-type(12) {
            margin-right: 0;
          }
        }
        .videoItemWrap{
          /*height: calc(100% - 33px);*/
          height: calc(100% - 70px);
        }
        videoItemWrap0{
          text-align: center;
        }
        .videoItem{
          padding: 1px;
          box-sizing: border-box;
          width: 100%;
          height: 100%;
        }
        .pagination{
          position: absolute;
          bottom: 1px;
          right: 15px;
        }
      }
    }
  }
  .footer {
    margin-top: 20px;
    color: #ffffff;
    font-size: 16px;

    .info {
      .select {
        width: 52px;
        height: 35px;
      }

      .select /deep/ .el-input__inner {
        padding-left: 5px;
        padding-right: 0;
      }

      .select /deep/ .el-input__icon {
        width: 15px;
      }

      .select /deep/ .el-select__caret {
        /*transform:rotate(270deg);*/
        /*color: black;*/
      }

      .select /deep/ .el-select__caret.is-reverse {
      }
    }

    .paging {
      /*background-color: pink;*/
      text-align: right;
      padding-right: 30px;
      margin-top: -20px;

      & /deep/ .el-pagination.is-background .btn-prev {
        background: none;
        border: 1px solid rgba(0, 255, 255, 1);
      }

      & /deep/ .el-pagination.is-background .btn-next {
        background: none;
        border: 1px solid rgba(0, 255, 255, 1);
      }

      & /deep/ .el-pager li {
        background: none;
        border: 1px solid rgba(0, 255, 255, 1);
      }

      & /deep/ .el-pagination__total,
      & /deep/ .el-pagination__sizes {
        float: left;
        font-size: 1.6rem;
        height: 35px;
        line-height: 35px;
      }

      & /deep/ .el-input__inner {
        height: 35px;
      }

      & /deep/ .el-input .el-input__inner {
        padding-right: 20px;
        color: #ffffff;
        font-size: 1.6rem;
      }
    }
  }
</style>
